home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / overview / dave falkenburg's sprocket / lib / splashwindow.cp < prev    next >
Encoding:
Text File  |  2000-09-28  |  2.7 KB  |  95 lines

  1. /*
  2.     File:        SplashWindow.cp
  3.  
  4.     Contains:    a simple splash screen window
  5.  
  6.     Written by: Dave Falkenburg    
  7.  
  8.     Copyright:    Copyright © 1993-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 8/19/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 11/16/94    DRF                Add (StringPtr) cast to make PPCC happier.
  21.                 11/12/94    DRF                Use NewColorOrBlackAndWhiteWindow.
  22.                 11/8/94        DRF                Deal with a missing splash picture.
  23.                 9/27/94        DRF                 AppLib.h is now Sprocket.h
  24.                 9/9/94        DRF                Reordered headers and removed redundant #includes.
  25.  
  26.  
  27. */
  28.  
  29. #include "Sprocket.h"
  30. #include "SplashWindow.h"
  31.  
  32. #include <ToolUtils.h>
  33. #include <Resources.h>
  34.  
  35.  
  36. TSplashWindow::TSplashWindow()
  37.     {
  38.     this->CreateWindow(kNormalWindow);
  39.     }
  40.  
  41.  
  42. TSplashWindow::~TSplashWindow()
  43.     {
  44.     if (fSplashPicture)
  45.         DisposeHandle((Handle) fSplashPicture);
  46.  
  47.     this->Close();
  48.     }
  49.  
  50.  
  51. WindowPtr
  52. TSplashWindow::MakeNewWindow(WindowPtr behindWindow)
  53.     {
  54.     GrafPtr        oldPort;
  55.     Rect        splashPictRect,windowRect;
  56.     WindowPtr    splashWindow;
  57.     
  58.     GetPort(&oldPort);
  59.  
  60.     fSplashPicture = GetPicture(kSplashPictureID);
  61.     
  62.     if (fSplashPicture)
  63.         {
  64.         MoveHHi((Handle) fSplashPicture);                        //    get it out of the way
  65.         splashPictRect = (**fSplashPicture).picFrame;
  66.         }
  67.     else
  68.         SetRect(&splashPictRect,0,0,0,0);
  69.         
  70.     //    normalize the rectangle
  71.     OffsetRect(&splashPictRect,-splashPictRect.left,-splashPictRect.top);
  72.  
  73.     //    center it on the main screen
  74.     windowRect = splashPictRect;
  75.     OffsetRect(&windowRect,((qd.screenBits.bounds.right-windowRect.right) >> 1),((qd.screenBits.bounds.bottom-windowRect.bottom) >> 1));
  76.     
  77.     splashWindow = NewColorOrBlackAndWhiteWindow(nil,&windowRect,(StringPtr) "\p",false,dBoxProc,behindWindow,false,(long) this);
  78.  
  79.     if (fSplashPicture)
  80.         {
  81.         DetachResource((Handle) fSplashPicture);    // need to do so we don’t botch the resource map after closing
  82.         SetWindowPic(splashWindow,fSplashPicture);    // in case an Alert comes up
  83.         }
  84.         
  85.     ShowWindow(splashWindow);
  86.     SetPort(splashWindow);
  87.     BeginUpdate(splashWindow);                    //    avoid a flashing update event later
  88.         if (fSplashPicture)
  89.             DrawPicture(fSplashPicture,&splashPictRect);
  90.     EndUpdate(splashWindow);                    //    avoid a flashing update event later
  91.  
  92.     SetPort(oldPort);
  93.     return splashWindow;
  94.     }
  95.